package IC.asm.operands;

import IC.asm.Visitor;

/**
 * Represents a label operand
 */
public class Label extends ImmOperand {
	private static int counter=0;
	private final String name;

	/**
	 * Create a label operand with a given name
	 * @param name the label name
	 */
	public Label(String name) {
		this.name = name;
	}

	/**
	 * Create a unique label
	 */
	public Label() {
		this.name = "_label_"+(++counter);
	}

	/**
	 * @return the name of the label
	 */
	public String getName() {
		return name;
	}

	@Override
	public <D, U> U accept(Visitor<D, U> v, D d) {
		return v.visit(this, d);
	}

	@Override
	public boolean equals(Object o)
	{
		if (! (o instanceof Label) )
			return false;
		return name.equals( ((Label)o).name );
	}
}
